//
//  TestPageViewController.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/3/14.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "TestPageViewController.h"
#import "ColorViewController.h"
#import "PageNode.h"
#import "SegmentView.h"
#import "SegmentViewConfigModel.h"
@interface TestPageViewController ()<PageNodeDelegate>

@property (nonatomic, assign) NSInteger scrollIndex  ;

@property (nonatomic, strong)  PageNode *page;

@property (nonatomic, strong) SegmentView *segmentView;
@end

@implementation TestPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];

   self.segmentView = [[SegmentView alloc] initWithFrame:CGRectMake(0, 64,CGRectGetWidth(self.view.frame) , 40 )
                               itemArr:@[@"时光书", @"时光书书",@"时光",@"PPT书",@"时光书书书"]
                           configModel:[[SegmentViewConfigModel alloc]init]];
    
    __weak TestPageViewController *weak_self = self;
    self.segmentView.didSelectBlock = ^(NSInteger index, NSString *currentItem) {
        [weak_self.page scrollToViewVontrollerAtIndex:index animated:YES];
    };
    [self.view addSubview:self.segmentView];

   self.page= [[PageNode alloc]init];
   self.page.frame = CGRectMake(0, 64+40, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-(64+ 40));
   self.page.delegate = self;
    
    [self.view addSubnode:self.page];

}

#pragma mark - PageNodeDelegate
-(NSInteger)numberOfPagesInPageNode:(PageNode *)pageNode{
    return self.segmentView.itemArr.count;
}

- (UIViewController *)pageNode:(PageNode *)pageNode viewControllAtIndex:(NSInteger)index{
    
    ColorViewController *colorVc = [[ColorViewController alloc]init];
    colorVc.indexString = [NSString stringWithFormat:@"%ld",index];
    return colorVc;
}

-(void)pageNode:(PageNode *)pageNode scrollToIndex:(NSInteger)index byPercent:(CGFloat)percent{
    
    [self.segmentView segmetViewUpdateToIndex:index byPercent: percent];
    
}

-(void)pageNode:(PageNode *)pageNode didSelectViewControllerAtIndex:(NSInteger)index{
    [self.segmentView scrollToIndex:index];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
